<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>for循环</title>
</head>
<body>
    <ul>
        {# |reverse : 反转列表输出顺序 #}
        {% for user in users|reverse %}
            <li>{{ user }}</li>
        {% endfor %}
    </ul>

    <br>

    <table>
        <thead>
            <tr>
                <th>用户名</th>
                <th>年龄</th>
                <th>国家</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                {% for value in person.values() %}
                    <td>{{ value }}</td>
                {% endfor %}
            </tr>
        </tbody>
    </table>

    <br>

    <table>
        <thead>
            <tr>
                <th>序号</th>
                <th>书名</th>
                <th>作者</th>
                <th>价格</th>
            </tr>
        </thead>
        <tbody>
            {% for book in books %}
                {% if loop.first %}
                    <tr style="background: red" >
                {% elif loop.last %}
                    <tr style="background: yellow" >
                {% else %}
                    <tr>
                {% endif %}
                        <td>{{ loop.index }}</td>
                        <td>{{ book.name }}</td>
                        <td>{{ book.author }}</td>
                        <td>￥{{ book.price }}</td>
                    </tr>
            {% endfor %}
        </tbody>
    </table>

    <br>

    {% for value in null_list %}
        <p>{{ value }}</p>
    {% else %}
        <p>没有任何值</p>
    {% endfor %}

    <br>

    <table>
        <tbody>
            {% for x in range(1, 10) %}
                <tr>
{#                    {% for y in range(1, x + 1) if y <= x %}#}
                    {% for y in range(1, 10) if y <= x %}
                        <td style="border:1px solid #999;"> {{ y }}*{{ x }} = {{ x*y }} </td>
                    {% endfor %}
                </tr>
            {% endfor %}
        </tbody>
    </table>

</body>
</html>